home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.amiga.programmer
- Path: comp.vuw.ac.nz!HERMES!maths!peterm
- From: peterm@maths.grace.cri.nz (Peter McGavin)
- Subject: Re: AddIntServer + VERTB strangeness
- Message-ID: <PETERM.96Apr17120442@tui.maths.irl.cri.nz>
- Date: 17 Apr 1996 00:04:42 GMT
- References: <PETERM.96Apr7124019@tui.maths.irl.cri.nz>
- <1084.6678T720T2089@Redrobe.demon.co.uk>
- Organization: Industrial Research Ltd
- In-reply-to: Mike@Redrobe.demon.co.uk's message of 14 Apr 96 12:00:41 +0000
-
- Mike@Redrobe.demon.co.uk (Mike Redrobe) writes:
- >could you perhaps post (or upload to aminet) an input handler source?
- >This seems to be the "major" overhead, and may go some way to convince people
- >to use this method, over "more common" throttle the OS methods..
-
- I'm not near my Amiga at the moment, but here's some C code clipped
- from one of my sources (and slightly rearranged --- sorry if I
- introduced any bugs).
- --
- Peter McGavin. (p.mcgavin@irl.cri.nz)
- ------------------------------------------------------------------------
-
- #include <devices/input.h>
-
- struct Interrupt input_handler;
- struct MsgPort *mp = NULL;
- struct IOStdReq *io = NULL;
- BOOL input_is_open = FALSE;
-
- __interrupt __asm /* __saveds */
- struct InputEvent *handler (register __a0 struct InputEvent *ie,
- register __a1 APTR data)
- /* This handler is passed a -list- of input events. Handlers are allowed to
- selectively remove individual entries or even add new entries. Returning
- NULL simply removes the lot. Use __saveds to access globals (or better
- still, pass everything required in a structure pointed to by data).
- The RKMs recommend writing input-handlers in asm for speed, because
- input-handlers are called often. */
- {
- while (ie != NULL) {
- /* grab raw keyboard/mouse/timer input from ie->ie_Class and
- other input-event fields here */
- ie = ie->ie_NextEvent;
- }
- return NULL;
- }
-
- BOOL install_handler (void)
- {
- if ((mp = CreatePort (NULL, 0)) == NULL)
- return FALSE;
- if ((io = (struct IOStdReq *)CreateExtIO (mp, sizeof(struct IOStdReq))) == NULL)
- return FALSE;
- if (OpenDevice ("input.device", 0, (struct IORequest *)io, 0) != 0)
- return FALSE;
- input_is_open = TRUE;
- input_handler.is_Code = (void (*)())handler;
- input_handler.is_Data = NULL; /* pass any pointer you want to the handler here */
- input_handler.is_Node.ln_Pri = 100; /* handlers are called in priority order */
- /* Intuition and console.device handlers are about priority 50, from memory */
- input_handler.is_Node.ln_Name = "my_input_handler";
- io->io_Data = &input_handler;
- io->io_Command = IND_ADDHANDLER;
- DoIO ((struct IORequest *)io);
- return TRUE;
- }
-
- void cleanup_handler (void)
- /* call cleanup_handler() even if install_handler() fails */
- {
- int i;
-
- if (input_is_open) {
- io->io_Data = &input_handler;
- io->io_Command = IND_REMHANDLER;
- DoIO ((struct IORequest *)io);
- CloseDevice ((struct IORequest *)io);
- input_is_open = FALSE;
- }
- if (io != NULL) {
- DeleteExtIO ((struct IORequest *)io);
- io = NULL;
- }
- if (mp != NULL) {
- DeletePort (mp);
- mp = NULL;
- }
- }
- --
- Peter McGavin. (p.mcgavin@irl.cri.nz)
-
-